Public Class MainForm

    Dim Counter As Integer
    Private Sub ShowChildFormToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowChildFormToolStripMenuItem.Click
        Counter = Counter + 1
        Dim frm As New SubForm
        frm.MdiParent = Me
        frm.Text = "Child Window :" & Counter
        frm.Show()
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    
    Private Sub ShowNormalFormToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowNormalFormToolStripMenuItem.Click
        Dim frm As Form = New FreeForm()
        frm.Show()
    End Sub

    Private Sub DynamicFormToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DynamicFormToolStripMenuItem.Click
        Dim frm As Form = New Form()
        frm.Text = "Form tự sản xuất"
        frm.Name = "DynamicForm"
        AddHandler frm.Click, AddressOf FormClick
        frm.Show()
    End Sub

    Private Sub FormClick(ByVal sender As Object, ByVal e As System.EventArgs)
        MsgBox("Chào bạn, Chương trình tự sinh ra tôi!")
    End Sub

    Private Sub MainForm_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Select Case e.CloseReason
            Case CloseReason.ApplicationExitCall

            Case CloseReason.FormOwnerClosing
            Case CloseReason.WindowsShutDown
            Case CloseReason.UserClosing
        End Select
        MsgBox(e.CloseReason)
    End Sub

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ShowInTaskbar = False
    End Sub
End Class
